<?php

require_once 'Custom/Model/Db.php';

class Member extends Custom_Model_Db
{
	/**
	 * The default table name 
	 */
	protected $_primary 			=	'uid';
    protected $_name 				= 	'member';
    protected $_dependentTables	=	array(	'Category',
    										'Favor',
    										'Guestbook',
    										'Person',
    										'Broker',
    										'Company',
    										'Memberlog');
    
    
    public function getAjaxData($roleid=1,$where = null, $order = null, $count = null, $offset = null)
	{
		try {
           	$db = $this->getAdapter();
           	switch ($roleid) {
           		case '2':
           			$obj=$db->select()
					->from(array('m'=>$this->dbprefix.'member'),'*')
					->joinLeft(array('c'=>$this->dbprefix.'company'),'m.uid=c.uid',array("uid as comuid","company","contact","telephone","mobile"))
					->where($where)
					->order($order)
					->limit($count, $offset);
           		break;
           		
           		default:
           			$obj=$db->select()
					->from(array('m'=>$this->dbprefix.'member'),'*')
					->joinLeft(array('p'=>$this->dbprefix.'person'),'m.uid=p.uid',array("uid as peruid","gender","job"))
					->where($where)
					->order($order)
					->limit($count, $offset);
           		break;
           	}

			//echo $obj->__toString();	
			
			$array=$db->fetchAll($obj);
			return $array;
        } catch (Exception $e) {
			return false;
        }
	}
	
	public function getMemberById($id){
		try {
			$db = $this->getAdapter();
			$obj=$db->select()
					->from(array('m'=>$this->dbprefix.'member'),'*')
					->joinLeft(array('c'=>$this->dbprefix.'company'),'m.uid=c.uid',array("uid as comuid","company","contact","telephone","mobile"))
					->where("m.uid=$id");
			$array=$db->fetchRow($obj);
			//echo $obj->__toString();
			
			//print_r($array);
			return $array;	
		} catch (Exception $e) {
			return false;
        }
	}
	
	
	public function getMemberInfoById($id){
		try {
			$db = $this->getAdapter();
			$obj=$db->select()
					->from(array('m'=>$this->dbprefix.'member'),'*')
					->joinLeft(array('c'=>$this->dbprefix.'company'),'m.uid=c.uid')
					->where("m.uid=$id");
			$array=$db->fetchAll($obj);
			
			return $array;	
		} catch (Exception $e) {
			return false;
        }
	}

	
   
    
}
